package zzh.com.kangkenuo.newutlis;

import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import zzh.com.kangkenuo.MyApplication;
import zzh.com.kangkenuo.R;
import zzh.com.kangkenuo.utils.WxShareAndLoginUtils;

/**
 * @author zzh
 * @Name:
 * @Description:
 * @date
 * @time
 * @copyright
 */
public class PopuUtlis implements View.OnClickListener {
    public PopupWindow popupWindow;
    public RelativeLayout rl_shera;
    public LinearLayout ll_shear_f, ll_shear_s, ll_shear_p;

    public static PopuUtlis instence;

    public static PopuUtlis getInstence() {
        if (instence == null)
            instence = new PopuUtlis();
        return instence;
    }

    public PopupWindow getPopupWindow(View id) {
        popupWindow = new PopupWindow(returnView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        //防止虚拟软键盘被弹出菜单遮住
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置PopupWindow的弹出和消失效果
        popupWindow.setAnimationStyle(R.style.AnimBottom);
        popupWindow.showAtLocation(id, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        return popupWindow;
    }

    public View returnView() {
        View view = LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.shear_layout, null);
        rl_shera = view.findViewById(R.id.rl_shera);
        ll_shear_f = view.findViewById(R.id.ll_shear_f);
        ll_shear_s = view.findViewById(R.id.ll_shear_s);
        ll_shear_p = view.findViewById(R.id.ll_shear_p);
        ll_shear_f.setOnClickListener(this);
        ll_shear_s.setOnClickListener(this);
        ll_shear_p.setOnClickListener(this);
        rl_shera.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_shera:
                popupWindow.dismiss();
                break;
            case R.id.ll_shear_p:
                popupWindow.dismiss();
                break;
            case R.id.ll_shear_s:
                popupWindow.dismiss();
                break;
            case R.id.ll_shear_f:
                WxShareAndLoginUtils.WxTextShare("测试微信分享", WxShareAndLoginUtils.WECHAT_MOMENT);
                popupWindow.dismiss();
                break;
        }
    }


}
